package cn.appsys.service.version;

import cn.appsys.dao.info.InfoMapper;
import cn.appsys.dao.version.VersionMapper;
import cn.appsys.pojo.Version;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import java.util.List;
@Service
public class VersionServiceImpl implements VersionService {
    @Resource
    private VersionMapper versionMapper;
    @Resource
    private InfoMapper infoMapper;
    @Override
    public List<Version> getVersionList(Integer appId) {
        return versionMapper.findVersionList(appId);
    }

    @Override
    public boolean appVersionSave(Version version) {
        boolean flag=false;
        Integer versionId=null;
        if(versionMapper.saveAppVersion(version)>0){
            flag=true;
            versionId=version.getId();
        }
        System.out.println("version====================="+versionId);
        if(infoMapper.updateVersionId(versionId,version.getAppId())>0){
            flag=true;
        }else{
            flag=false;
        }
        return flag;
    }

    @Override
    public Version getVersionById(Integer id) {
        return versionMapper.findAppVersionById(id);
    }

    @Override
    public boolean delVersionAPK(Integer id) {
        return versionMapper.removeAPK(id)>0;
    }

    @Override
    public boolean updateVersion(Version version) {
        return versionMapper.upVersion(version)>0;
    }

    @Override
    public boolean delVersionByAppId(Integer appId) {
        return versionMapper.removeVersionByappId(appId)>0;
    }
}
